package kr.hkit.androidcomplete03.ETC;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.Chronometer;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.TimePicker;

public class WidgetTest extends Activity {
	Chronometer chrono;
	Button btnStart, btnEnd;
	RadioButton rdoCal, rdoTime;
	CalendarView calView;
	TimePicker tPicker;
	TextView tvYear, tvMonth, tvDay, tvHour, tvMinute;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.widgettest);
		
		btnStart = (Button) findViewById(R.id.btnStart);
		btnEnd = (Button) findViewById(R.id.btnEnd);
		
		chrono = (Chronometer) findViewById(R.id.chronometer1);
		
		rdoCal = (RadioButton) findViewById(R.id.radioCal);
		rdoTime = (RadioButton) findViewById(R.id.radioTime);
		
		calView = (CalendarView) findViewById(R.id.calendarView1);
		tPicker = (TimePicker) findViewById(R.id.timePicker1);
		
		tvYear = (TextView) findViewById(R.id.tvYear);
		tvMonth = (TextView) findViewById(R.id.tvMonth);
		tvDay = (TextView) findViewById(R.id.tvDay);
		tvHour = (TextView) findViewById(R.id.tvHour);
		tvMinute = (TextView) findViewById(R.id.tvMinute);
		
		tPicker.setVisibility(View.INVISIBLE);
		calView.setVisibility(View.INVISIBLE);
		
		rdoCal.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				tPicker.setVisibility(View.INVISIBLE);
				calView.setVisibility(View.VISIBLE);
			}
			
		});
		
		rdoTime.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				tPicker.setVisibility(View.VISIBLE);
				calView.setVisibility(View.INVISIBLE);
			}
		});
		
		btnStart.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				chrono.setBase(SystemClock.elapsedRealtime());
				chrono.start();
				chrono.setTextColor(Color.RED);
			}
			
		});
		
		btnEnd.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				chrono.stop();
				chrono.setText(Color.BLUE);
				
				java.util.Date curDate = new java.util.Date(calView.getDate());
				
				tvYear.setText(Integer.toString(1900 + curDate.getYear()));
				tvMonth.setText(Integer.toString(1 + curDate.getMonth()));
				tvDay.setText(Integer.toString(curDate.getDate()));
				
				tvHour.setText(Integer.toString(tPicker.getCurrentHour()));
				tvMinute.setText(Integer.toString(tPicker.getCurrentMinute()));
			}
			
		});
	}
}
